package com.woniu.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.woniu.order.mapper.OrderMapper;
import com.woniu.order.pojo.Coupons;
import com.woniu.order.mapper.CouponsMapper;
import com.woniu.order.service.ICouponsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 优惠券表 服务实现类
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Service
public class CouponsServiceImpl extends ServiceImpl<CouponsMapper, Coupons> implements ICouponsService {


    @Autowired(required = false)
    private CouponsMapper couponsMapper;

    @Autowired(required = false)
    private RedisTemplate redisTemplate;

    @Override
    public boolean queryCouponsType(Long id) {
        boolean b = couponsMapper.queryCouponsType(id);
        return false;
    }

    @Override
    public List<Coupons> listSeckill() {
        // 1. 查询的开始时间必须大于当前时间
        LambdaQueryWrapper<Coupons> wrapper = new LambdaQueryWrapper<>();
        wrapper.ge(Coupons::getStartTime,new Date());
        // 2. 商品的状态必须是进行中的
        wrapper.eq(Coupons::getStatus,0);
        // 3. 秒杀的库存数量必须大于0
        wrapper.ge(Coupons::getStock,1);
        // 4. 查询数据
        List<Coupons> seckillList = couponsMapper.selectList(wrapper);
        return seckillList;
    }

    @Override
    public boolean updateCouponsById(Integer id) {
        return couponsMapper.updateCouponsById(id);
    }

}
